import { localStorage } from "../../../utils/storage.js";
import { MyModel } from "../../../modules/my.js";

const _localStorage = new localStorage();

export class Common extends MyModel {
  // 获取简历
  getResume() {
    let resume = _localStorage.getItem("resume");
    if (resume) {
      return resume;
    }
  }
  // 获取简历id
  getRid() {
    let rid = _localStorage.getItem("rid") || "";
    if (rid) {
      return rid;
    }
  }
  // 简历是否完整
  hasResume() {
    return new Promise((resolve, reject) => {
      this.getResumes().then(res => {
        if (res.code == 2) {
          res = res.data;
          let nullResume = []; // 保存空值的数组
          let resume = [
            "name",
            "telphone",
            "sex",
            "birthday",
            "workAge",
            "jobStatus",
            "education",
            "specialty",
            "nativePlace",
            "hopeWorkAddress",
            "politicsStatus",
            "email",
            "selfDesc"
          ];
          resume.forEach(value => {
            if (res.resume[value] == "null" || res.resume[value] == "") {
              nullResume.push(value);
            }
          });
          if (nullResume.length > 6) {
            wx.showModal({
              title: "简历信息不完整！",
              content: "是否前去补充完整简历",
              mask: true,
              success: res => {
                if (res.confirm) {
                  wx.redirectTo({
                    url: "/pages/my/setresume/index/index"
                  });
                }
              }
            });
            resolve(false);
          }
          resolve(true);
        } else if (res.data == null) {
          wx.showModal({
            title: "简历信息不完整！",
            content: "是否前去创建简历",
            mask: true,
            success: res => {
              if (res.confirm) {
                wx.redirectTo({
                  url: "/pages/my/createresume/index"
                });
              }
            }
          });
          resolve(false);
        } else {
          reject(false);
        }
      });
    });
  }
}
